package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.SafetyBean;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/18.
 */

public class SafetyCheckResultsAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<SafetyBean> safetyBeanList;

    public SafetyCheckResultsAdapter(Context context, List<SafetyBean> safetyBeanList) {
        this.context = context;
        this.safetyBeanList = safetyBeanList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return safetyBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return safetyBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = inflater.inflate(R.layout.item_safety_results, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SafetyBean safetyBean = safetyBeanList.get(position);
        holder.nameTv.setText(safetyBean.getName());
        holder.delIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                safetyBeanList.remove(position);
                notifyDataSetChanged();
            }
        });
        holder.delIv.setVisibility(View.GONE);
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.name_tv)
        HXTextView nameTv;
        @BindView(R.id.del_iv)
        ImageView delIv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
